package com.serkol.abmanager.libraries;

import com.serkol.abmanager.entity.Goods;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;

public class Utils {

    public static String getHostPath(HttpServletRequest request) {
        String host = "";
        host = request.getScheme() +"://" + request.getServerName()
                + ":" +request.getServerPort();
        System.out.println("Utils host:" +host);
        return host;
    }

    public static String getClickKey(String appid){
        Calendar instance = Calendar.getInstance();
        StringBuilder builder=new StringBuilder();
        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH);
        int day = instance.get(Calendar.DAY_OF_MONTH);
        int hour = instance.get(Calendar.HOUR);
        int minut = instance.get(Calendar.MINUTE);
        int scond = instance.get(Calendar.SECOND);
        builder.append(appid);
        builder.append(year);
        builder.append(month);
        builder.append(day);
        builder.append(hour);
        builder.append(month);
        builder.append(scond);

        String s = builder.toString();
        String s1 = s.toUpperCase();
        return s1;


    }
    public static String getRfId(Goods goods){
        Calendar instance = Calendar.getInstance();
        StringBuilder builder=new StringBuilder();
        int year = instance.get(Calendar.YEAR);
        int month = instance.get(Calendar.MONTH);
        int day = instance.get(Calendar.DAY_OF_MONTH);
        int hour = instance.get(Calendar.HOUR);
        int minut = instance.get(Calendar.MINUTE);
        int scond = instance.get(Calendar.SECOND);
        //QR20212021918104619|3|2200
        builder.append("QR");
        builder.append(year);
        builder.append(year);
        builder.append(month);
        builder.append(day);
        builder.append(hour);
        builder.append(minut);
        builder.append(scond);
        builder.append("|");
        builder.append(goods.getType());
        builder.append("|");
        builder.append(new Double(goods.getWeight()).intValue());



        String s = builder.toString();
        String s1 = s.toUpperCase();
        return s1;


    }
}